<template>
  <span>
    {{ getSelectItem(col.selectData, row[col.prop]) }}
  </span>
</template>

<script>
export default {
  name: 'TdSelectData',
  components: {},
  props: {
    col: {
      type: Object,
      default: () => {}
    },
    row: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {

    }
  },
  methods: {
    getSelectItem(data, val) {
      if (Array.isArray(data) && val !== undefined) {
        const item = data.find(one => one.value === val)
        if (item && item.label) {
          return item.label
        }
        return '--'
      }
      if (data === undefined) {
        console.error(`components/table.vue error: 当type="selectData"时，必须传入选项列表selectData数组，例：
        {
          label: "类型",
          prop: "discountType",
          type: "selectData",
          selectData: [
            {
              label: '全部状态',
              value: ''
            },
            {
              label: '已上线',
              value: 0
            },
            {
              label: '已下线',
              value: 1
            },
            {
              label: '已过期',
              value: 2
            },
          ]
        }`)
      }
      return '--'
    }
  }
}
</script>

<style lang='scss' scoped>

</style>
